<?php
/**
 * Default控制器
 * Created By Terry
 * 2008-12-24
 */

class defaultCtrl extends Controller {
    var $testModel;
    
    function indexAct() {
        $this->testModel = $this->loader->model('test');
        
        $this->output->set('teststr',$this->testModel->getTestString());
        $this->output->set('welcome',__('Welcome to Simple PHP!'));
        $this->loader->view('default.php');
    }

    function testAct($p = '1'){
        $pagination =& $this->loader->lib('page');

        echo $pagination->fetch(100,$p,site_url('default/test/[#page#]'),1000);
        exit;
    }

    function cacheAct(){
        $cache =& $this->loader->lib('cache');
        $cache->set('test',array('this is a test','my'));
        print_r($cache->get('test'));
    }

    function validateAct(){
        $test_rule = 
"title  |标题     |string=类型不正确!|require=必须要填写!|length(8:)=长度只能大于8! length(:20)=长度只能小于20!
age     |年龄     |digits=年龄类型不正确!|require|size(10:80)
email   |email地址|email      |require|
addtime |时间     |time       |require|time_format(Y-m-d)=时间格式不正确
ipaddr  |IP地址   |ipv4       |       |
password|密码     |string     |require|equal(title)=密码不相等! length(6:)=密码长度不正确!
a       |测试a    |float      |       |length(0:199.99) test(5)=设置错误
b       |用户名   |username=用户信息错误!|       |";

        $validator =& $this->loader->lib('validator');

        $arr = array(
            'title' => 'asdffsdfsdfsdfsdfsdfsdfsdfsdfsd',
            'age' => '21d',
            'email' => 'baol_ing@yeah.net',
            'password'=> 'asdff',
            'addtime' => '2009-6-30',
            'a' => 6,
            'b' => 'Baoling'
        );

        if($validator->validate($arr,$test_rule)){
            echo "\n success";
        }else{
            echo "\n falied\n";
            print_r($validator->getMsg());
        }
        //var_dump($validator->errmsg);
    }
}